package de.haw.ai3.bs.aufgabe3.a2;

import java.util.HashSet;

import de.haw.ai3.bs.aufgabe3.a2.table.ReentrantTable;
import de.haw.ai3.bs.aufgabe3.a2.table.SynchronizedTable;
import de.haw.ai3.bs.aufgabe3.a2.table.Table;


public class Starter {

	private static final int SMOKER_NO = 3;
	
	private static final boolean REENTRENT = true;
	private static final int SIMULATION_DURATION_SEC = 45;

	public static void main(String[] args) {
		Table table = null;
		
		if (REENTRENT){
			// Aufgabenteil 2
			table = new ReentrantTable();
		}else{
			// Aufgabenteil 1
			table = new SynchronizedTable();
		}

		HashSet<Zutat> zutaten = new HashSet<Zutat>();
		zutaten.add(Zutat.MACTHES);
		zutaten.add(Zutat.PAPER);
		zutaten.add(Zutat.TOBACCO);

		Agent agent = new Agent(zutaten, table);
		agent.start();

		HashSet<Smoker> smoker = new HashSet<Smoker>();
		for (int i = 0; i < SMOKER_NO; i++) {
			Smoker tempSmoker = new Smoker(i, Zutat.values()[i], table);
			tempSmoker.start();
			smoker.add(tempSmoker);
		}

		try {
			Thread.currentThread();
			Thread.sleep((SIMULATION_DURATION_SEC * 1000));
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		for (Smoker smoker2 : smoker) {
			smoker2.interrupt();
		}
		agent.interrupt();
		
		System.out.println("\n\t PROGRAMM BEENDET");
	}
}
